<!-- 报产作业：针车报产查询11 -->
<template>
	<view class="container">

		<h5>组别</h5>
		<uv-input @tap="showSelect" v-model="group" disabled disabledColor="#ffffff" placeholder="请选择组别">
		</uv-input>

		<h5>指令</h5>
		<uv-input v-model="lotNo" placeholder="请输入指令"></uv-input>

		<h5>缴库日期</h5>
		<uv-datetime-picker :formatter="formatter" v-model="value" ref="datetimePicker" mode="date" @confirm="confirm">
		</uv-datetime-picker>
		<uv-datetime-picker :formatter="formatter" v-model="value2" ref="datetimePicker2" mode="date"
			@confirm="confirm2">
		</uv-datetime-picker>
		<view class="flex">
			<uv-input @tap="open" v-model="dateValue" placeholder="请选择开始时间" disabled disabledColor="#ffffff"></uv-input>
			<uv-icon name="more-dot-fill"></uv-icon>
			<uv-input @tap="open2" v-model="dateValue2" placeholder="请选择结束时间" disabled
				disabledColor="#ffffff"></uv-input>
		</view>

		<uv-action-sheet ref="groupSelect" :actions="groups" title="请选择组别" @select="groupSelect">
		</uv-action-sheet>

		<view class="btns">
			<button @click="search" class="button">搜索</button>
			<button @click="reset" class="buttonRS">重置</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: Number(new Date()),
				value2: Number(new Date()),
				dateValue: '',
				dateValue2: '',
				lotNo: '',
				groups: [],
				group: '',
				userInfo: {}
			}
		},
		methods: {
			// 组别选择
			showSelect() {
				this.$refs.groupSelect.open();
			},
			// 组别选择返回结果
			groupSelect(e) {
				this.group = e.name;
			},
			open() {
				this.$refs.datetimePicker.open();
			},
			confirm(e) {
				this.dateValue = this.formatDate(e.value)
			},
			open2() {
				this.$refs.datetimePicker2.open();
			},
			confirm2(e) {
				this.dateValue2 = this.formatDate(e.value)
			},
			formatDate(timestamp) {
				let date = new Date(timestamp);
				let year = date.getFullYear();
				let month = "0" + (date.getMonth() + 1); // getMonth()返回的月份是从0开始的，这里添加前导零
				let day = "0" + date.getDate(); // 添加前导零
				return year + "-" + month.substr(-2) + "-" + day.substr(-2); // substr(-2)确保至少取两位数字，避免月份或日期是个位数时的问题
			},
			search() {
				uni.navigateTo({
					url: '/pages/reportProductSearch/reportProductSearch?deptName=' + this.group.split('  ')[0] +
						'&deptNo=' + this.group.split('  ')[1] + '&lotNo=' + this
						.lotNo + '&dateStart1=' + this.dateValue + '&dateEnd1=' + this.dateValue2
				})
			},
			reset() {
				this.lotNo = ''
				this.dateValue = ''
				this.dateValue2 = ''
			},
			getGroupsList() {
				this.userInfo = uni.getStorageSync('userInfo')
				this.group = this.userInfo.departmentList[0].deptName + '  ' + this.userInfo.departmentList[0].deptNo
				let token = uni.getStorageSync('token')
				uni.request({
					url: '/kl/pad/stitchDate/getDeptNameList',
					header: {
						'Authorization': token //自定义请求头信息
					},
					method: "GET",
					success: (res) => {
						// console.log(res)
						if (res.data.code === 200) {
							for (let i = 0; i < res.data.data.list.length; i++) {
								res.data.data.list[i].name = res.data.data.list[i].deptName + '  ' + res.data
									.data
									.list[i].deptNo
							}
							this.groups = res.data.data.list
						} else {
							this.$refs.notify.show({
								message: res.data.message
							});
						}
					}
				});
			},

		},
		onShow() {
			this.getGroupsList();
		},
		onReady() {}
	}
</script>

<style>
	.flex {
		display: flex;
		align-items: center;
	}

	.container {
		padding: 30rpx;
	}

	h5 {
		margin: 30rpx 0;
	}

	.btns {
		margin-top: 100rpx;
		display: flex;
		justify-content: space-between;
	}
</style>